var t = getApp(), a = require("../../../component/WxNotificationCenter/WxNotificationCenter.js");

Page({
    data: {
        currentTab: 0,
        total: -1,
        pageNo: 1,
        listDatas: [],
        total2: -1,
        listDatas2: [],
        pageNo2: 1,
        swiperheight: 1100
    },
    loadData: function(a) {
        var e = this, o = e.data.pageNo;
        if (a) o = 1; else if (e.data.total == e.data.listDatas.length) return;
        t.network.post({
            url: t.url.listMeSendOrder,
            params: {
                pageNo: o,
                type: 1,
                pageSize: 10
            },
            before: function() {
                wx.showNavigationBarLoading();
            },
            success: function(n) {
                if (1 == n.data.result) {
                    var s = [];
                    a || (s = e.data.listDatas), s = s.concat(n.data.data.sendOrders), console.log(s), 
                    o += 1, e.setData({
                        total: n.data.data.total,
                        listDatas: s,
                        pageNo: o
                    });
                } else t.util.showToast(n.data.message);
            },
            fail: function() {
                t.util.showToast("获取数据失败");
            },
            complete: function() {
                wx.hideNavigationBarLoading(), wx.stopPullDownRefresh();
            }
        });
    },
    loadMore: function() {
        console.log("loadMore"), this.loadData(!1);
    },
    loadMore2: function() {
        console.log("loadMore2"), this.loadData2(!1);
    },
    loadData2: function(a) {
        var e = this, o = e.data.pageNo2;
        if (a) o = 1; else if (e.data.total2 == e.data.listDatas2.length) return;
        t.network.post({
            url: t.url.listMeSendOrder,
            params: {
                pageNo: o,
                type: 2,
                pageSize: 10
            },
            before: function() {
                wx.showNavigationBarLoading();
            },
            success: function(n) {
                if (1 == n.data.result) {
                    var s = [];
                    a || (s = e.data.listDatas2), s = s.concat(n.data.data.sendOrders), console.log(s), 
                    o += 1, e.setData({
                        total2: n.data.data.total,
                        listDatas2: s,
                        pageNo2: o
                    });
                } else t.util.showToast(n.data.message);
            },
            fail: function() {
                t.util.showToast("获取数据失败");
            },
            complete: function() {
                wx.hideNavigationBarLoading(), wx.stopPullDownRefresh();
            }
        });
    },
    cancelOrder: function(a) {
        var e = this;
        t.network.post({
            url: t.url.cancelSendOrder,
            params: {
                sendOrderId: a
            },
            before: function() {
                wx.showLoading({
                    title: "正在取消"
                });
            },
            success: function(o) {
                if (wx.hideLoading(), 1 == o.data.result) {
                    var n = e.data.listDatas;
                    console.log(n);
                    for (var s = 0; s < n.length; s++) if (n[s].sendOrderId == a) {
                        n[s].state = "0";
                        break;
                    }
                    console.log(n), e.setData({
                        listDatas: n
                    });
                } else t.util.showToast(o.data.message);
            },
            fail: function() {
                wx.hideLoading(), t.util.showToast("获取数据失败");
            },
            complete: function() {
                wx.hideNavigationBarLoading(), wx.stopPullDownRefresh();
            }
        });
    },
    bindCancel: function(t) {
        var a = t.currentTarget.dataset.state;
        if (console.log(a), "1" == a) {
            var e = this;
            wx.showModal({
                title: "提示",
                content: "确定取消订单？",
                success: function(a) {
                    a.confirm && e.cancelOrder(t.currentTarget.dataset.orderid);
                }
            });
        }
    },
    clickIng: function(t) {
        this.setData({
            currentTab: 0
        });
    },
    clickEnd: function(t) {
        -1 == this.data.total2 && this.loadData2(!0), this.setData({
            currentTab: 1
        });
    },
    bindView: function(t) {
        var a = t.currentTarget.dataset.orderid, e = t.currentTarget.dataset.index;
        wx.navigateTo({
            url: "../qianOrder/qianOrder?orderId=" + a + "&index=" + e
        });
    },
    bindCall: function(t) {
        var a = t.currentTarget.dataset.phone;
        wx.makePhoneCall({
            phoneNumber: a
        });
    },
    swiperChange: function(t) {
        1 == t.detail.current && -1 == this.data.total2 && this.loadData2(!0), this.setData({
            currentTab: t.detail.current
        });
    },
    onLoad: function(t) {
        var e = this;
        wx.getSystemInfo({
            success: function(t) {
                console.log(t.model), console.log(t.pixelRatio), console.log(t.windowWidth), console.log(t.windowHeight), 
                console.log(t.language), console.log(t.version), console.log(t.platform), e.setData({
                    swiperheight: 2 * t.windowHeight - 80
                });
            }
        }), this.loadData(!0), a.addNotification("didSelectOrderClient", this.didSelect, this);
    },
    didSelect: function(t) {
        var a = t.index, e = this.data.listDatas;
        console.log(t), console.log(e[a]), e[a].state = 1, e[a].selectUserName = t.selectUserName, 
        e[a].selectUserAccessToken = t.selectUserAccessToken, e[a].selectUserAvatar = t.userAvatar, 
        e[a].selectUserPhone = t.selectUserPhone, this.setData({
            listDatas: e
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {}
});